import 'package:flutter/material.dart';

class HeroAnimation extends StatelessWidget {
  final List<String> photos;

  const HeroAnimation({Key key, @required this.photos}) : super(key: key);
  Widget build(BuildContext context) {
    var timeDilation = 5.0; // 1.0 means normal animation speed.
    var listPhotos = <Widget>[
      for (var photo in photos)
        new PhotoHero(
          photo: photo,
          width: 300.0,
          onTap: () {
            Navigator.of(context).push(
                new MaterialPageRoute<Null>(builder: (BuildContext context) {
              return new Scaffold(
                appBar: new AppBar(
                  title: const Text('Flippers Page'),
                ),
                body: new Container(
                  // The blue background emphasizes that it's a new route.
                  color: Colors.lightBlueAccent,
                  padding: const EdgeInsets.all(16.0),
                  alignment: Alignment.topLeft,
                  child: new PhotoHero(
                    photo: photo,
                    width: 100.0,
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ),
              );
            }));
          },
        ),
    ];
    return new Scaffold(
      appBar: new AppBar(
        title: const Text('Basic Hero Animation'),
      ),
      body: new Center(
        child: ListView.builder(
            itemCount: photos.length, itemBuilder: (_, i) => listPhotos[i]),
      ),
    );
  }
}

class PhotoHero extends StatelessWidget {
  const PhotoHero({Key key, this.photo, this.onTap, this.width})
      : super(key: key);

  final String photo;
  final VoidCallback onTap;
  final double width;

  Widget build(BuildContext context) {
    return new SizedBox(
      width: width,
      child: new Hero(
        tag: photo,
        child: new Material(
          color: Colors.transparent,
          child: new InkWell(
            onTap: onTap,
            child: new Image.asset(
              photo,
              fit: BoxFit.contain,
            ),
          ),
        ),
      ),
    );
  }
}
